package com.neuedu.boot.mapper;


import com.neuedu.boot.entity.Menu;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.Date;
import java.util.List;
import java.util.Map;

public interface MenuMapper {


    @Select(value = "select * from menu ")
    List<Map> list();

    @Select(value = "select * from menu ")
    @Results(
            id = "resultMap",
            value = {
                    @Result(id = true,column = "menu_id", property = "menuId", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
                    @Result(column = "url", property = "url", javaType = String.class, jdbcType = JdbcType.VARCHAR),
                    @Result(column = "active", property = "active", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
                    @Result(column = "parent_id", property = "parentId", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
                    @Result(column = "menu_type", property = "menuType", javaType = String.class, jdbcType = JdbcType.VARCHAR),
                    @Result(column = "createtime", property = "createtime", javaType = Date.class, jdbcType = JdbcType.TIMESTAMP),
            }
    )
//    @One() //association
//    @Many //collection
    List<Menu> listEntity();



    @Select(value = "select * from menu where 1=1 ")
    @ResultMap(value="resultMap")
    List<Menu> listEntity2();


    /**
     * root=menu{
     *     menuName,
     *     url
     * }
     * root{
     *     param1=menu{
     *       menuName
     *     }
     *     param2=map
     * }
     *
     *
     *
     *
     * @param menu
     * @return
     */
    @Insert(
            value = "insert into menu(menu_name, url, parent_id,  menu_type) values(#{menuName} ,#{url} ,#{parentId},#{menuType})"
    )
    int save( Menu menu);

    @Insert(
            value = "insert into menu(menu_name, url, parent_id,  menu_type) values(#{menu.menuName} ,#{menu.url} ,#{menu.parentId},#{menu.menuType})"
    )
    int save2(@Param("menu") Menu menu);


}
